﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TC4T_WinForm
{
    public partial class LoginForm : C1.Win.C1Ribbon.C1RibbonForm
    {
        public string UserName = "";
        public string Password = "";
        public LoginForm()
        {
            InitializeComponent();
            this.tb_password.ReadOnly = false;
            this.tb_username.ReadOnly = false;
            this.tb_password.Text= Password;
            this.tb_username.Text = UserName;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            UserName = tb_username.Text;
            Password = tb_password.Text;
            MyTCSession.InitSession();
            Teamcenter.Soa.Client.Model.Strong.User _user = MyTCSession.Login(UserName, Password, "", "", "");
            if (_user != null)
                this.Close();
            else
            {
                c1SuperLabel3.Visible = true;
            }
        }

        //private void LoginForm_KeyUp(object sender, KeyEventArgs e)
        //{
        //    if (e.KeyCode == Keys.Enter)
        //    {
        //        UserName = tb_username.Text;
        //        Password = tb_password.Text;
        //    }
        //}

        //private void tb_password_KeyUp(object sender, KeyEventArgs e)
        //{
        //    if (e.KeyCode == Keys.Enter)
        //    {
        //        UserName = tb_username.Text;
        //        Password = tb_password.Text;
        //    }
        //}

        private void tb_username_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                UserName = tb_username.Text;
                Password = tb_password.Text;
            }
        }

        private void tb_password_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.c1Button1.PerformClick();
            }
        }

        private void LoginForm_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                c1Button1.PerformClick();
            }
        }
    }
}
